package com.cf.user.controller;

import com.cf.common.result.Result;
import com.cf.system.feign.RoleFeign;
import com.cf.user.dto.UserDTO;
import com.cf.user.entity.User;
import com.cf.user.service.UserService;
import com.cf.user.vo.UserVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ChenFeng
 * @date 2021/11/5 5:25 下午
 * @description
 */
@RestController
@AllArgsConstructor
public class UserController {

    private final UserService userService;

    private final RoleFeign roleFeign;

    @GetMapping("/info")
    public Result<UserVO> info() {
        User user = userService.getById(1123598821738675201L);
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return Result.success(userVO);
    }

    @GetMapping("/user/detail")
    public Result<UserDTO> detail() {
        User user = userService.getById(1123598821738675201L);
        List<String> roleNamesByRoleIds = roleFeign.getRoleNamesByRoleIds(user.getRoleId());
        System.out.println(roleNamesByRoleIds);
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(user, userDTO);
        userDTO.setRoles(roleNamesByRoleIds);
        return Result.success(userDTO);
    }

}
